package com.zhuangwe.task;

import com.xiaoleilu.hutool.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务
 *
 * @author LeviCoder
 * @create 2019-01-30 14:46
 */
@Slf4j
@Component
public class TaskJob
{
    /**
     * 每隔 10 s 执行一次
     */
    @Scheduled(cron = "0/10 * * * * ?")
    public void job1(){
        log.info("【job1】开始执行：{}", DateUtil.formatDateTime(new Date()));
    }

    /**
     * 间隔 2 s 执行
     * 固定间隔
     */
    @Scheduled(fixedRate = 2000)
    public void job2(){
        log.info("【job2】开始执行：{}",DateUtil.formatDateTime(new Date()));
    }

    /**
     * 延迟 5s 后间隔 4s 执行
     * 固定等待时间
     */
    @Scheduled(fixedDelay = 4000,initialDelay = 5000)
    public void job3(){
        log.info("【job3】开始执行：{}",DateUtil.formatDateTime(new Date()));
    }

}
